<template>
  <div class="login-wrap">
    <el-form class="login-container">
      <h1 class="title">用户注册</h1>
      <el-form-item>
        <el-input
          type="text"
          placeholder="用户账号"
          v-model="username"
          auto-complete="off"
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-input
          type="password"
          placeholder="密码"
          v-model="password"
          auto-complete="off"
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-input
          type="password"
          placeholder="确认密码"
          v-model="password1"
          auto-complete="off"
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="doRegister" style="width: 48%"
          >注册</el-button
        >
        <el-button type="primary" @click="doLogin" style="width: 48%"
          >去登陆</el-button
        >
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { SignUp } from '../api/index'
import { ElMessage, ElMessageBox } from 'element-plus'

export default {
  name: 'RegisterView',
  data: function () {
    return {
      username: '',
      password: '',
      password1: '',
    }
  },
  methods: {
    doRegister: function () {
      var user = {
        username: this.username,
        password: this.password,
      }
      //校验用户输入......

      SignUp(user)
        .then((res) => {
          ElMessageBox.alert(res.msg, '提示信息', {
            // if you want to disable its autofocus
            autofocus: false,
            confirmButtonText: '确认',
          })
          if (res.code == 1) {
            this.$router.push('/login')
          }
        })
        .catch()
    },
    doLogin: function () {
      this.$router.push('/login')
    },
  },
}
</script>

<style scoped>
.login-wrap {
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  padding-top: 10%;
  background-image: url();
  /* background-color: #112346; */
  background-repeat: no-repeat;
  background-position: center right;
  background-size: 100%;
}

.login-container {
  border-radius: 10px;
  margin: 0px auto;
  width: 350px;
  padding: 30px 35px 15px 35px;
  background: #fff;
  border: 1px solid #eaeaea;
  text-align: left;
  box-shadow: 0 0 20px 2px rgba(0, 0, 0, 0.1);
}

.title {
  margin: 0px auto 40px auto;
  text-align: center;
  color: #505458;
}
</style>
